package td;

import java.util.ArrayList;

import ui.WindTrapView;

/*
 * Class for Windtrap. In addition to it's parent it has a StatusEffects attribute to show
 * if it has upgraded with rainbow stone and became able to slow. The pushback attribute gives
 * how many can it push enemies back.
 * */
public class WindTrap extends Trap {
	//StatusEffects to indicate slowing ability.
	public StatusEffects status;
	//int to indicate amount of push.
	public int pushback;
	
	public WindTrap(){
		super();
		this.cooldownTime=40;
		this.status=StatusEffects.None;
		this.pushback=1;
		this.viewable = new WindTrapView(this);
	}
	
	public WindTrap(Field position) {
		super(position);
		this.cooldownTime=40;
		this.status=StatusEffects.None;
		this.pushback=1;
		this.viewable = new WindTrapView(this);
	}
	
	/*Upgrades windtrap with given magicstone. With rainbow it gains slow effect.*/
	public void upgrade(MagicStones stone) {
		this.stone=stone;
		switch(stone){
		case Blue:
			ArrayList<Field> neighbours = this.position.neighbours;
			for(int i=0; i<neighbours.size(); i++){
				Field current = neighbours.get(i);
				if(current.isRoad && !current.hasTrap){
					current.addElement(new WindTrap(current));
					current.hasTrap=true;
				}
			}
			this.wasUpgraded=true;
			break;
		case Red:
			this.pushback=2;
			this.wasUpgraded=true;
			break;
		case Yellow:
			this.cooldownTime-=(this.cooldownTime/2);
			if(this.cooldownTime<0)
				this.cooldownTime=0;
			this.wasUpgraded=true;
			break;
		case Rainbow:
			this.status=StatusEffects.Slow;
			this.wasUpgraded=true;
			break;
		}
	}
}
